package com.nbicc.module.config;

import com.nbicc.module.interceptor.CorsInterceptor;
import com.nbicc.module.interceptor.MyShiroInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by li on 17/12/25.
 */
@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurerAdapter {

    @Autowired
    private MyShiroInterceptor authenticationInterceptor;
    @Autowired
    private CorsInterceptor corsInterceptor;

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        authenticationInterceptor.addIntoRegistry(registry);
        corsInterceptor.addIntoRegistry(registry);
        super.addInterceptors(registry);
    }

    /**
     * 配置静态文件映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
}
